<template>
	<view class="container">
		<view class="wid100 dis disAl disJuC" style="height: 140rpx;">
			<view class="wid90 hei80 dis disAl borRad40 bacFFF foSi25">
				<view class="wid20 dis disJuC">
					<icon type="search" size="14" />
				</view>
				<input class="wid70" @input="onKeyInput" placeholder="请输入想搜索的内容" />
			</view>
		</view>
		<scroll-view scroll-y="true" @scrolltolower="lower" style="height: calc(100vh - 140rpx);">
			<view class="wid90 mar bacFFF borRad20 mar-bott20" @click.stop="tiaozhuan('/pages/noticedetail/index?id=' + item.id)"
				v-for="(item, index) in noticelist" :key="index" style="padding: 30rpx 0;">
				<view class="wid90 mar">
					<view class="foSi30 fowebl">{{ item.title }}</view>
					<view class="mar-top30 wid100 overflowHidden foSi25 liH40" style="color: #5B5B5B;">{{ item.brief }}</view>
				</view>
			</view>
			<view v-if="noticelist.length == 0" class="wid90 mar fowe800 foSi35">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/imgs/icon/zanwu1.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<view class="hei20"></view>
			<view class="hei20"></view>
		</scroll-view>
	</view>
</template>

<script>
	import { Notice } from '../../model/notice-model.js';
	var notice = new Notice();
	export default {
		data() {
			return {
				last_page: 0,
				page: 1,
				noticelist: [],
				timer: null,
				title: ''
			};
		},
		onLoad: function(e) {
			this.getlist()
		},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			this.page = 1
			this.getlist()
		},
		methods: {
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				});
			},
			onKeyInput(e){
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.title = e.target.value
					console.log(that.title)
					that.page = 1
					that.getlist()
				}, 1000)
			},
			getlist(){
				var that = this
				var params = {
					page: that.page,
					keyword: that.title
				};
				notice.getNoticeList((data) => {
					console.log(data)
					if (data.code === 1) {
						that.last_page = data.data.last_page
						that.noticelist = that.page === 1?data.data.data:that.noticelist.concat(data.data.data)
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						})
					}
					uni.stopPullDownRefresh();
				}, params)
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getlist()
				}
			},
		}
	};
</script>
<style>
	.container {
		height: 100vh;
		background-color: #F7F7F7;
	}
	.bott{
		width: 140rpx;
		height: 50rpx;
		border: 2rpx solid #646666;
		color: #646666;
	}
	.bottCor{
		border-color: #FF0000;
		color: #FF0000;
	}
</style>